package XML.T4;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.*;

public class T4 {

    public static void main(String[] args) throws Exception {

        ArrayList<Phone>list = new ArrayList<>();

        SAXReader sr = new SAXReader();
        Document doc = sr.read("phones.xml");
        Element rootElement = doc.getRootElement();
        List<Element> elements = rootElement.elements();
        for (Element e : elements) {
            Phone p = new Phone(e.elementText("name"),
                    e.elementText("brand"),
                    e.elementText("size"),
                    e.elementText("price"),
                    e.elementText("color"));
            list.add(p);
        }

        Map<Integer,String>map = new HashMap<>();
        map.put(1,"黑色");
        map.put(2,"白色");
        map.put(3,"银色");
        map.put(4,"金色");
        map.put(5,"退出");

        Scanner sc = new Scanner(System.in);
        System.out.println("1,黑色  2,白色  3,银色  4,金色  5,退出");
        int s = sc.nextInt();

        for (Integer i : map.keySet()) {
            for (Phone p : list) {
                if (map.get(s).equals(p.getColor())){
                    System.out.println(p);
                    return;
                }
                if (s==5){
                    System.exit(0);
                }
            }
        }
        System.out.println("没有该颜色的手机");

    }
}
